//
// Created by wangjunjun on 2024/3/11.
//

#ifndef  LCMCMD_H
#define  LCMCMD_H
#include <lcm/lcm-cpp.hpp>
#include "control_parameter_request_lcmt.hpp"
#include "control_parameter_respones_lcmt.hpp"
#include <iostream>
#include <boost/format.hpp>

#include <sys/socket.h>

#include "csignal"

#include <iostream>
#include <sstream>
#include <cstring>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cstdint>
#include <openssl/md5.h>
#include <iomanip>
#include <chrono>

#include <sys/select.h>
#include <fcntl.h>
#include <memory>
#include <mutex>
#include <unistd.h>
class ClcmCmd {
public:
    //设置单例模式获取资源数据
    static std::shared_ptr<ClcmCmd> GetInStance();
public:
    void Start();
    void dance_start(lcm::LCM &lcm, control_parameter_request_lcmt &_parameter_request_lcmt, double value);
    void dance_gait_number(lcm::LCM &lcm, control_parameter_request_lcmt &_parameter_request_lcmt, double value);
    //Vec4f
    void dance_offset_y(lcm::LCM &lcm, control_parameter_request_lcmt &_parameter_request_lcmt, float * value);
    //Vec4f
    void dance_swing_height(lcm::LCM &lcm, control_parameter_request_lcmt &_parameter_request_lcmt, float * value);
    //Vec3D
    void dance_v_des(lcm::LCM &lcm, control_parameter_request_lcmt &_parameter_request_lcmt, double * value);

    // 计算CRC32校验值
    std::string calculateCRC32(const std::string &data);
private:
    ClcmCmd();
    ~ClcmCmd();
    void sigHandler(int signum);
    static void signalHandler(int signum);
private:
    static std::shared_ptr<ClcmCmd> m_Instance;
    static std::once_flag m_flag;
    control_parameter_request_lcmt m_parameter_req;
    float  m_speed_x;
    float  m_speed_y;
    float  m_speed_w;
    int m_goal_callback_flag;
    int m_dog_cur_status;
    double m_v_des_lcm[3];
    float m_swing_height_lcm[4];
    float m_offset_y_lcm[4];
    float m_w_z[5];
    int m_cout=0;
    int m_port;
    struct sockaddr_in m_serverAddr, m_clientAddr;
    int m_udpSocket;
};


#endif //WLROBOTICS_LCMCMD_H